<template>
  <!-- 为 ECharts 准备一个定义了宽高的 DOM -->
  <div id="main" style="width: 100%; height: 400px"></div>
</template>

<script lang="ts" setup>
import { ref, onMounted, reactive } from "vue";
import apis from "@/http/apis";
import _ from "lodash"; // JavaScript 实用工具库。用来合并两个对象
import * as echarts from "echarts"; //导入可视化工具echarts

onMounted(async () => {
  // 基于准备好的dom，初始化echarts实例
  var myChart = echarts.init(document.getElementById("main") as HTMLElement);
  // 指定图表的配置项和数据
  //请求到的图表数据需要合并
  let { data: Mydata }: any = await apis.getReportData();
  console.log(Mydata, "66");
  // 需要合并的选项
  let options = {
    title: {
      text: "用户来源",
    },
    tooltip: {
      trigger: "axis",
      axisPointer: {
        type: "cross",
        label: {
          backgroundColor: "#E9EEF3",
        },
      },
    },
    grid: {
      left: "3%",
      right: "4%",
      bottom: "3%",
      containLabel: true,
    },
    xAxis: [
      {
        boundaryGap: false,
      },
    ],
    yAxis: [
      {
        type: "value",
      },
    ],
  };
  const result = _.merge(Mydata, options);
  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(result);
});
</script>

<style lang="less" scoped></style>
